	set more off

use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	gen Pcum = cuminstalla/TotalHouse_interp
	gen cumarea= cuminstalla/area
	gen cuminstsq= cuminst*cuminst
	
	label variable Pcum "Solar Panels per Dwelling"
	label variable cuminstsq "Solar Panels (000s) $^2$"
	label variable cumarea "Solar Panels (000s) per km$^2$"
		
	
	
	
	merge m:1 postcode using Data/SA3postcode.dta
	keep if _merge ==3
	
	by SA3_CODE quarter, sort: egen SA3_cum = total(cuminstall)

	gen SA3_cumnotpostcode = SA3_cum - cuminstal

	label variable SA3_cumnotpostcode "Solar Panels (Rest of Municipality, 000s)"

	
	
	
	
	
	xi: xtivreg2 green_p cuminstall  i.quarter  [aweight =NCust	] , fe cluster(postcode) 

	
	summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")   ///
	keep(*cum* median_*) addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes replace
 

 
 
	
 
	xi: xtivreg2 green_p cuminstall  i.quarter median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp	 [aweight =NCust	] , fe cluster(postcode) 

	
	quietly summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")   ///
	keep(*cum* median_* P*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
		
	
	************
	
	* nonlinear
	
	xi: xtivreg2 green_p cuminstall cuminstsq i.quarter  [aweight =NCustomer	] , fe cluster(postcode) 

	
	quietly summ green_plan [aweight =NCustomer	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")   ///
	keep(*cum* median_*) addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 

 	
		
	*************
	
	*PCUM
	
	
	xi: xtivreg2 green_p Pcum  i.quarter  [aweight =NCust	], fe cluster(postcode) ffirst 

	
	quietly summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")   ///
	keep(*cum* median_* P*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
 
 
 
	
	
	
	
	
	************
	
	*cumarea 
	
		

	
	
	xi: xtivreg2 green_p cumarea   i.quarter  [aweight =NCust	], fe cluster(postcode) ffirst 

	
	quietly summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")  ///
	keep(*cum* median_* P*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
 
 
	
	
	
	***********
	
	*neighboring effects
	
	
	
	xi: xtivreg2 green_p cuminstall SA3_cumnotpostcode  i.quarter  [aweight =NCust	] , fe cluster(postcode) 

	
	summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
	
	outreg2 using Analysis/FE_pcode_models, bdec(3) label ctitle("FE")  ///
	keep(*cum* median_* P*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
	
	
	*************
	
 
	
	
	
 
	
	
